package com.itcast.yygh.hosp.controller;

import com.itcast.common.result.R;
import com.itcast.yygh.hosp.service.HospitalService;
import com.itcast.yygh.model.model.hosp.Hospital;
import com.itcast.yygh.model.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 医疗项目后台管理系统医院列表模块的显示
 */

@Api("医院管理模块")
@RestController
@RequestMapping("/admin/hosp/hospital")
//@CrossOrigin
public class HospitalController {
    //引入service的依赖
    @Resource
    private HospitalService hospitalService;

    //医院数据分页查询
    @ApiOperation("医院数据分页查询")
    @PostMapping("/findPage/{page}/{limit}")
    public R findPage(@PathVariable Integer page , @PathVariable Integer limit, @RequestBody HospitalQueryVo hospitalQueryVo){
        //调用service查询数据的分页
        Page<Hospital>  pages = hospitalService.findPage(page,limit,hospitalQueryVo);
        //返回对应结果
        return R.ok().data("pages",pages);
    }
    //更新医院的状态
    @ApiOperation("更新医院的状态")
    @GetMapping("/updateStatus/{id}/{status}")
    public R updateStatus(@PathVariable("id") String id , @PathVariable("status") Integer status){
        //调用更新方法
        try{
            hospitalService.updateStatus(id,status);
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
        return R.ok();
    }
    //查询医院详情方法
    @ApiOperation("查询医院详情数据")
    @GetMapping("/show/{id}")
    public R  show(@PathVariable("id")String id){
        //调用查询数据的方法
        Map<String,Object> hospital = hospitalService.show(id);
        return R.ok().data("hospital",hospital);
    }
}
